
function do_sm3_encrypt(a) {
	var sm3 = doSM3Hash(a);
	return sm3.toLowerCase();
}
function do_sm2_encrypt(a,sm2_public_key) {
	var b = "";
	"undefined" !== typeof a
			&& null != a
			&& 0 < a.length
			&& (
			b = doEncrypt(a,sm2_public_key, 1)
					);
	return b;
}

/**
 * 生成随机字符串用于传输密码
 */
/*function getRandomString(len) {
	/!*len = len || 32;
	// 默认去掉了容易混淆的字符0oLi,9qg,vV,uU,I1
	var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
	// 第一字符最大长度
	var maxPos = chars.length;
	var p = '';
	// 循环拼接字符串
	for (var i = 0; i <= len - 1; i++) {
		p += chars.charAt(Math.floor(Math.random() * maxPos));
	}
	return p;*!/
    var randomNum = (function(){
        var today = new Date();
        var seed = today.getTime();
        function rnd(){
            seed = ( seed * 9301 + 49297 ) % 233280;
            return seed / ( 233280.0 );
        };
        return function rand(number){
            return Math.ceil(rnd(seed) * number);
        };
    })();
    return randomNum;
}*/

function do_encrypt(message, encryptmode, pubKey) {
	// 表示开启安全校验
	if (encryptmode == "true") {
		var sm3message = do_sm3_encrypt(message);
		var randomStr = getRandomString(8);
		message = sm3message + randomStr + message;
	}
	return do_sm2_encrypt(message, pubKey);
}